package com.summer.filesync.security;

import java.time.LocalDateTime;

/** 用户实体类 表示系统中的用户信息 */
public class User {
  private final String username;
  private final String passwordHash;
  private final String salt;
  private final UserRole role;
  private final String description;
  private final boolean enabled;
  private final LocalDateTime createdAt;
  private LocalDateTime lastLoginTime;

  public User(
      String username,
      String passwordHash,
      String salt,
      UserRole role,
      String description,
      boolean enabled) {
    this.username = username;
    this.passwordHash = passwordHash;
    this.salt = salt;
    this.role = role;
    this.description = description;
    this.enabled = enabled;
    this.createdAt = LocalDateTime.now();
    this.lastLoginTime = null;
  }

  public String getUsername() {
    return username;
  }

  public String getPasswordHash() {
    return passwordHash;
  }

  public String getSalt() {
    return salt;
  }

  public UserRole getRole() {
    return role;
  }

  public String getDescription() {
    return description;
  }

  public boolean isEnabled() {
    return enabled;
  }

  public LocalDateTime getCreatedAt() {
    return createdAt;
  }

  public LocalDateTime getLastLoginTime() {
    return lastLoginTime;
  }

  public void updateLastLoginTime() {
    this.lastLoginTime = LocalDateTime.now();
  }

  @Override
  public String toString() {
    return String.format(
        "User{username='%s', role=%s, enabled=%s, createdAt=%s}",
        username, role, enabled, createdAt);
  }
}
